ostbuild: Add tree-to-bin and bin-to-src
authorColin Walters <walters@verbum.org>
Tue, 1 May 2012 14:02:34 +0000 (10:02 -0400)
committerColin Walters <walters@verbum.org>
Fri, 4 May 2012 20:16:16 +0000 (16:16 -0400)
Makefile-ostbuild.am
src/ostbuild/pyostbuild/builtin_bin_to_src.py
src/ostbuild/pyostbuild/builtin_tree_to_bin.py [new file with mode: 0755]
src/ostbuild/pyostbuild/builtins.py
src/ostbuild/pyostbuild/main.py

index a22791637c8ff8740a7f6b75a919baf9ed9abc55..21ec7b46511db9819f6c29d860dbe74b950d6c7e 100644 (file)
@@ -33,6 +33,7 @@ pyostbuild_PYTHON =                                   \
        src/ostbuild/pyostbuild/builtin_prefix.py       \
        src/ostbuild/pyostbuild/builtin_resolve.py      \
        src/ostbuild/pyostbuild/builtin_modify_snapshot.py      \
+       src/ostbuild/pyostbuild/builtin_tree_to_bin.py  \
        src/ostbuild/pyostbuild/builtin_status.py       \
        src/ostbuild/pyostbuild/builtins.py             \
        src/ostbuild/pyostbuild/filemonitor.py          \
index b8cbb0a4d66b38ff944cdb694324300ff783919e..d3b75b26bbdc4e10aaa9a3366013b2366aa82d1a 100755 (executable)
@@ -71,6 +71,8 @@ class OstbuildBinToSrc(builtins.Builtin):
         self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
 
         snapshot = self.bin_snapshot_to_src(self.bin_snapshot)
-        json.dump(snapshot, sys.stdout, indent=4, sort_keys=True)
+        db = self.get_src_snapshot_db()
+        path = db.store(snapshot)
+        log("Source snapshot: %s" % (path, ))
 
 builtins.register(OstbuildBinToSrc)
diff --git a/src/ostbuild/pyostbuild/builtin_tree_to_bin.py b/src/ostbuild/pyostbuild/builtin_tree_to_bin.py
new file mode 100755 (executable)
index 0000000..f25f2e3
--- /dev/null
@@ -0,0 +1,57 @@
+# Copyright (C) 2011,2012 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# ostbuild-compile-one-make wraps systems that implement the GNOME build API:
+# http://people.gnome.org/~walters/docs/build-api.txt
+
+import os,sys,stat,subprocess,tempfile,re,shutil
+import argparse
+from StringIO import StringIO
+import json
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from .subprocess_helpers import run_sync, run_sync_get_output
+from . import buildutil
+
+class OstbuildTreeToBin(builtins.Builtin):
+    name = "tree-to-bin"
+    short_description = "Turn a tree into a binary snapshot"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('--prefix')
+        parser.add_argument('--tree')
+
+        args = parser.parse_args(argv)
+        self.parse_config()
+        if args.prefix:
+            self.prefix = args.prefix
+
+        if args.tree:
+            self.load_bin_snapshot_from_path(args.tree)
+        else:
+            self.load_bin_snapshot_from_current()
+
+        db = self.get_bin_snapshot_db()
+        path = db.store(self.bin_snapshot)
+        log("Binary snapshot: %s" % (path, ))
+
+builtins.register(OstbuildTreeToBin)
index c71431fd3e98cac58a84a97113e02446603d635c..4c3f5021d03096d2413428720b9936d64703871c 100755 (executable)
@@ -92,7 +92,14 @@ class Builtin(object):
         self.snapshot_dir = os.path.join(self.workdir, 'snapshots')
         self.patchdir = os.path.join(self.workdir, 'patches')
 
-    def parse_active_branch(self):
+    def load_bin_snapshot_from_path(self, path):
+        self.bin_snapshot_path = os.path.join(path, 'contents.json')
+        self.bin_snapshot = json.load(open(self.bin_snapshot_path))
+        bin_ver = self.bin_snapshot['00ostree-bin-snapshot-version']
+        if bin_ver != 0:
+            fatal("Unhandled 00ostree-bin-snapshot-version \"%d\", expected 0", bin_ver)
+
+    def load_bin_snapshot_from_current(self):
         if self.ostree_dir is None:
             fatal("/ostree directory not found")
         repo_path = os.path.join(self.ostree_dir, 'repo')
@@ -101,11 +108,8 @@ class Builtin(object):
         self.repo = repo_path
         if self.active_branch is None:
             fatal("No \"current\" link found")
-        branch_path = os.path.join(self.ostree_dir, self.active_branch)
-        contents_path = os.path.join(branch_path, 'contents.json')
-        f = open(contents_path)
-        self.active_branch_contents = json.load(f)
-        f.close()
+        tree_path = os.path.join(self.ostree_dir, self.active_branch)
+        self.load_bin_snapshot_from_path(tree_path)
 
     def get_component_snapshot(self, name):
         found = False
index 63827c1b45b1e0e52903598a999eacf2780c75c3..2a60f85da6a711ddbd544e113bd61c652bc1ef08 100755 (executable)
@@ -33,6 +33,7 @@ from . import builtin_pull_components
 from . import builtin_prefix
 from . import builtin_resolve
 from . import builtin_modify_snapshot
+from . import builtin_tree_to_bin
 from . import builtin_status
 
 def usage(ecode):